package com.ruoyi.goods.controller;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.payment.page.models.AlipayTradePagePayResponse;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.goods.utils.GetOrder;
import com.ruoyi.goods.vo.AliPayOrderVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping("/goods")
public class AliPayController {

    @GetMapping("/pay")
    public Object TradeWapPayRequest(AliPayOrderVo aliPayOrderVo) {
        AlipayTradePagePayResponse pay;
        try {
            pay = Factory.Payment.Page().pay(
                    aliPayOrderVo.getSubject(),
                    GetOrder.getOrderNo(),
                    "399.00",
                    aliPayOrderVo.getReturnUrl());
            return AjaxResult.success(pay.getBody());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("支付失败");
        }
        return "支付失败";
    }
}
